package com.fortune.common.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class StringValueOperations implements ValueOperations<String, String>{
	
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	
	@Override
	public void set(String key, String value) {
		stringRedisTemplate.opsForValue().set(key, value);
	}

	@Override
	public void set(String key, String value, long timeout, TimeUnit unit) {
		stringRedisTemplate.opsForValue().set(key, value, timeout, unit);
	}

	@Override
	public Boolean setIfAbsent(String key, String value) {
		return stringRedisTemplate.opsForValue().setIfAbsent(key, value);
	}

	@Override
	public void multiSet(Map<? extends String, ? extends String> m) {
		stringRedisTemplate.opsForValue().multiSet(m);
	}

	@Override
	public Boolean multiSetIfAbsent(Map<? extends String, ? extends String> m) {
		return stringRedisTemplate.opsForValue().multiSetIfAbsent(m);
	}

	@Override
	public String get(Object key) {
		return stringRedisTemplate.opsForValue().get(key);
	}

	@Override
	public String getAndSet(String key, String value) {
		return stringRedisTemplate.opsForValue().getAndSet(key, value);
	}

	@Override
	public List<String> multiGet(Collection<String> keys) {
		return stringRedisTemplate.opsForValue().multiGet(keys);
	}

	@Override
	public Long increment(String key, long delta) {
		return stringRedisTemplate.opsForValue().increment(key, delta);
	}

	@Override
	public Double increment(String key, double delta) {
		return stringRedisTemplate.opsForValue().increment(key, delta);
	}

	@Override
	public Integer append(String key, String value) {
		return stringRedisTemplate.opsForValue().append(key, value);
	}

	@Override
	public String get(String key, long start, long end) {
		return stringRedisTemplate.opsForValue().get(key, start, end);
	}

	@Override
	public void set(String key, String value, long offset) {
		stringRedisTemplate.opsForValue().set(key, value, offset);
	}

	@Override
	public Long size(String key) {
		return stringRedisTemplate.opsForValue().size(key);
	}

	@Override
	public RedisOperations<String, String> getOperations() {
		return stringRedisTemplate.opsForValue().getOperations();
	}

	@Override
	public Boolean setBit(String key, long offset, boolean value) {
		return stringRedisTemplate.opsForValue().setBit(key, offset, value);
	}

	@Override
	public Boolean getBit(String key, long offset) {
		return stringRedisTemplate.opsForValue().getBit(key, offset);
	}

}
